<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <title>登录若依系统</title>
    <meta name="description" content="若依后台管理框架">
    <link href="../static/css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
    <link href="../static/css/font-awesome.min.css" th:href="@{/css/font-awesome.min.css}" rel="stylesheet"/>
    <link href="../static/css/style.min.css" th:href="@{/css/style.min.css}" rel="stylesheet"/>
    <link href="../static/css/login.min.css" th:href="@{/css/login.min.css}" rel="stylesheet"/>
    <link href="../static/ruoyi/css/ry-ui.css" th:href="@{/ruoyi/css/ry-ui.css?v=4.7.3}" rel="stylesheet"/>
    <!-- 360浏览器急速模式 -->
    <meta name="renderer" content="webkit">
    <!-- 避免IE使用兼容模式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="shortcut icon" href="../static/favicon.ico" th:href="@{favicon.ico}"/>
    <style type="text/css">label.error { position:inherit;  }</style>
    <script>
        if(window.top!==window.self){alert('未登录或登录超时。请重新登录');window.top.location=window.location};
    </script>
</head>
<body class="signin">
    <div class="signinpanel">
        <div class="row">
            <div class="col-sm-7">
                <div class="signin-info">
                    <div class="logopanel m-b" style="margin-top:20px;margin-left:310px">
                        <h1><img alt="[非常规作业现场检验系统 ]" src="/ruoyi.png" style="width:425px"></h1>
                    </div>
                    <div class="m-b"></div>
                </div>
            </div>
            <div class="col-sm-5" style="margin-top: 20px;margin-left:380px">
                <form id="signupForm" autocomplete="off">
                    <h4 class="no-margins" style="color: black">登录：</h4>
                    <input type="text"     name="username" class="form-control uname"     placeholder="用户名" value="admin"    />
                    <input type="password" name="password" class="form-control pword"     placeholder="密码"   value="admin123" />
                    <button class="btn btn-success btn-block" id="btnSubmit" data-loading="正在验证登录，请稍候...">登录</button>
                </form>
            </div>
        </div>
    </div>
<!--<script th:inline="javascript"> var ctx = [[@{/}]]; var captchaType = [[${captchaType}]]; </script>-->
    <script> var ctx = "\/"; var captchaType = "math"; </script>
<!--[if lte IE 8]><script>window.location.href=ctx+'html/ie.html';</script><![endif]-->
<!-- 全局js -->
    <script>
        var captchaType = "math";
        var ctx = "\/";
    </script>
    <script src="../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
    <script src="../static/js/bootstrap.min.js" th:src="@{/js/bootstrap.min.js}"></script>
    <!-- 验证插件 -->
    <script src="../static/ajax/libs/validate/jquery.validate.min.js" th:src="@{/ajax/libs/validate/jquery.validate.min.js}"></script>
    <script src="../static/ajax/libs/validate/messages_zh.min.js" th:src="@{/ajax/libs/validate/messages_zh.min.js}"></script>
    <script src="../static/ajax/libs/layer/layer.min.js" th:src="@{/ajax/libs/layer/layer.min.js}"></script>
    <script src="../static/ajax/libs/blockUI/jquery.blockUI.js" th:src="@{/ajax/libs/blockUI/jquery.blockUI.js}"></script>
    <script src="../static/ruoyi/js/ry-ui.js" th:src="@{/ruoyi/js/ry-ui.js?v=4.6.2}"></script>
    <script src="../static/ruoyi/login.js" th:src="@{/ruoyi/login.js}"></script>
    <script>
        var macKey = "ihaierForTodoKey";
        var imgcode = "ihaierForTodo_Iv";

        $(function () {
            validateKickout();
            validateRule();
        });

        $.validator.setDefaults({
            submitHandler: function () {
                login();
            }
        });

        function login() {
            $.modal.loading($("#btnSubmit").data("loading"));
            var username = $.common.trim($("input[name='username']").val());
            var password = $.common.trim($("input[name='password']").val());
            // var encrypt = CryptoJS.AES.encrypt(password, CryptoJS.enc.Utf8.parse(macKey), {
            //     iv: CryptoJS.enc.Utf8.parse(imgcode),
            //     mode: CryptoJS.mode.CBC,
            //     padding: CryptoJS.pad.Pkcs7
            // }).toString();
            // var yhdlm = CryptoJS.AES.encrypt(username, CryptoJS.enc.Utf8.parse(macKey), {
            //     iv: CryptoJS.enc.Utf8.parse(imgcode),
            //     mode: CryptoJS.mode.CBC,
            //     padding: CryptoJS.pad.Pkcs7
            // }).toString();
            $.ajax({
                type: "post",
                url: ctx + "login",
                data: {
                    "yhdlm": username,
                    "pwd": password,
                    //               "validateCode": validateCode
                    //               "rememberMe": false
                },
                success: function (r) {
                    if (r.code == 0) {
                        location.href = ctx + 'index';
                    }else if(r.msg=="密码强度不符合要求！"){
                        $.modal.msg(r.msg);
                        layer.open({
                            type : 2,
                            closeBtn:0,
                            btn: ['提交'],
                            shadeClose : false,
                            title : "密码强度不符合要求,请修改密码",
                            area : ["530px", "500px"],
                            yes: function (index, layero) {
                                var iframeWin = layero.find('iframe')[0];
                                console.log(iframeWin)
                                iframeWin.contentWindow.submitHandler(index, layero);

                            },
                            content : [ctx + "system/user/profile/resetPwd", 'no']
                        })
                    } else {
                        $.modal.closeLoading();
                        $('.imgcode').click();
                        $(".code").val("");
                        $.modal.msg(r.msg);
                    }
                }
            });

        }

        function validateRule() {
            var icon = "<i class='fa fa-times-circle'></i> ";
            $("#signupForm").validate({
                rules: {
                    username: {
                        required: true
                    },
                    password: {
                        required: true
                    }
                },
                messages: {
                    username: {
                        required: icon + "请输入您的用户名",
                    },
                    password: {
                        required: icon + "请输入您的密码",
                    }
                }
            })
        }

        function validateKickout() {
            if (getParam("kickout") == 1) {
                layer.alert("<font color='red'>您已在别处登录，请您修改密码或重新登录</font>", {
                        icon: 0,
                        title: "系统提示"
                    },
                    function (index) {
                        //关闭弹窗
                        layer.close(index);
                        if (top != self) {
                            top.location = self.location;
                        } else {
                            var url = location.search;
                            if (url) {
                                var oldUrl = window.location.href;
                                var newUrl = oldUrl.substring(0, oldUrl.indexOf('?'));
                                self.location = newUrl;
                            }
                        }
                    });
            }
        }

        function getParam(paramName) {
            var reg = new RegExp("(^|&)" + paramName + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return decodeURI(r[2]);
            return null;
        }
    </script>
</body>
</html>
